package com.qf.sclg.controller;

import com.qf.sclg.entity.Subject;
import com.qf.sclg.service.SubjectService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-10-12 16:35:06
 */
@RestController
@RequestMapping("subject")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Subject> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.subjectService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param subject 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Subject> add(Subject subject) {
        return ResponseEntity.ok(this.subjectService.insert(subject));
    }

    /**
     * 编辑数据
     *
     * @param subject 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Subject> edit(Subject subject) {
        return ResponseEntity.ok(this.subjectService.update(subject));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.subjectService.deleteById(id));
    }

}

